﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace Uranus.Common
{
    public class XmlDtcash
    {

        /// <summary>  
        /// 序列化  
        /// </summary>  
        /// <param name="type">类型</param>  
        /// <param name="obj">对象</param>  
        /// <returns></returns>  
        public static object Serializer(Type type, string path)
        {
            try
            {
                using (StreamReader streamReader = new StreamReader(path))
                {
                    using (XmlReader reader = XmlReader.Create(streamReader))
                    {
                        XmlSerializer formatter = new XmlSerializer(type);
                        return formatter.Deserialize(reader);
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }

    #region 实体类

    [Serializable]
    public class ArealDistribution
    {
        [XmlElement("AreaName")]
        public string AreaName
        {
            get;
            set;
        }

        [XmlElement("DistributionNumber")]
        public int DistributionNumber
        {
            get;
            set;
        }

        public decimal AreaRate
        {
            get;
            set;
        }
    }

    [Serializable]
    public class BarDistribution
    {
        public string BarName { get; set; }

        [XmlArray("BarButions")]
        public List<BarButionInfo> BarButions { get; set; }
    }
    
    [Serializable]
    public class BarButionInfo
    {
        public string ButionName { get; set; }

        public decimal ButionPrice { get; set; }

        public decimal ButionRate { get; set; }

        public string ButionColor { get; set; }
    }

    #endregion
}
